using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;


public partial class Admin_SuaCTDDAT : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
            loaddropdownlist();
        }
    }
    private void loaddropdownlist()
    {
        dr_tendd.DataSource = tbDiadanhBUS.GetAll();
        dr_tendd.DataTextField = tbDiadanhCollumn.tendiadanh.ToString();
        dr_tendd.DataValueField = tbDiadanhCollumn.madiadanh.ToString();
        dr_tendd.DataBind();
        dr_tendd.Items.Insert(0, new ListItem("All", "0"));


        dr_tenat.DataSource = tbAmthucBUS.GetAll();
        dr_tenat.DataTextField = tbAmthucCollumn.tenamthuc.ToString();
        dr_tenat.DataValueField = tbAmthucCollumn.maamthuc.ToString();
        dr_tenat.DataBind();
        dr_tenat.Items.Insert(0, new ListItem("All", "0"));
    }
    protected void btn_sua_Click(object sender, EventArgs e)
    {
        //try
        //{
        int id = int.Parse(Request.QueryString["id"].ToString());
        tbChitietdiadanhamthuc  ddat= tbCTdiadanhamthucBUS .GetByID(id);
        //tbDiadiem ddiem = new tbDiadiem();
        ddat.Madiadanh  = int.Parse(dr_tendd .SelectedValue);
        ddat .Maamthuc  = int .Parse (dr_tenat .SelectedValue );
        tbCTdiadanhamthucBUS .Update(ddat);

        //catch
        //{
        Response.Redirect("~/Admin/DanhsachCTDDAT.aspx");
        //}
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            txt_maddat.Text = id.ToString();

            tbChitietdiadanhamthuc  ddat = tbCTdiadanhamthucBUS .GetByID(id);
            dr_tendd .SelectedValue = ddat.Madiadanh .ToString();
            dr_tenat .SelectedValue =ddat .Mactdiadanhamthuc .ToString ();
        }
        catch
        {
            Response.Redirect("~/Admin/DanhsachCTDDAT.aspx");
        }
    }
}
